package leetcode

/*
 * @lc app=leetcode.cn id=989 lang=golang
 *
 * [989] 数组形式的整数加法
 */

// @lc code=start
func reverse(lst []int) {
	for i, n := 0, len(lst); i < n/2; i++ {
		lst[i], lst[n-1-i] = lst[n-1-i], lst[i]
	}
}

func addToArrayForm(A []int, K int) []int {
	for i := len(A) - 1; i >= 0 && K > 0; i-- {
		v := A[i] + K%10
		K /= 10
		if v > 9 {
			K++
		}
		A[i] = v % 10
	}
	for K > 0 {
		A = append([]int{K % 10}, A...)
		K /= 10
	}
	return A
}

// @lc code=end
